<?php
class Admin_Forms_UserAdminForm extends Zend_Form {
	function __construct($option = null) {
		$this->setAction('')
				->setMethod('POST')
				->setAttrib('enctype', 'multipart/form-data')
				->setAttrib('class', 'form-horizontal');
		$username = $this->createElement('text', 'username');
		$username->addValidator('alnum')
					->addValidator ( 'regex', false, array ('/^[a-z]+/' ) )
					->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Tài khoản');
		$name = $this->createElement('text', 'fullname');
		$name->setRequired ( true )
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'form-control')
		            ->setLabel('Tên');
        $password = $this->createElement ( 'password', 'password' );
		$password->addValidator ( 'StringLength', false, array (6,'messages' =>
                                      array(Zend_Validate_StringLength::TOO_SHORT => 'Mật khẩu không được phép ít hơn 6 ký tự')) )
				->setRequired ( true )
				->addValidator(
				        'NotEmpty',
				        true,
				        array('messages' => array('isEmpty' => 'Mật khẩu không được để trống'))
				    )
				->setLabel('Mật khẩu')
				->addFilter('StringTrim')
	            ->setAttrib('class', 'form-control')
				->setDescription('Tối thiểu là 6ký tự.
Chỉ sử dụng chữ và số');
        	$mail = $this->createElement('text', 'email');
		$mail->setRequired ( true )
					->addValidator('EmailAddress')
		            ->addFilter('StringTrim')
		            ->setAttrib('class', 'input-control')
		            ->setLabel('Email');     	     
		$submit = $this->createElement('submit','submit',array ('label' => $option['submit'] ));
		$submit->setAttrib('class', 'btn-default btn');
		$cancel = $this->createElement('button', 'cancel',array('label'	=> 'Hủy bỏ','class'=>'btn btn-default','onclick'	=> 'windown:location = "' . $option['cancel_link'] . '"'));
		$this->addElement($name);
		if ($option['submit'] == 'Thêm')
			$this->addElement($username)
					->addElement($password);
		$this->addElement($submit)
				->addElement($cancel);
		$this->setDecorators(array('FormElements',array('HtmlTag',array('tag'	=> 'div','width'=>'100%')),'form'));
		$this->setElementDecorators(array(
										'ViewHelper',
										'Errors',
										'Description',
										array(	
											array('data'	=> 'HtmlTag'),
											array('tag'		=> 'div','class'	=> 'col-md-6')),
										array('label',
											array('class'	=> 'col-md-2 control-label')),
										array(
											array('row'	=> 'HtmlTag',),
											array('class'=>'form-group')
		        						)
									)
								);
		$submit->setDecorators(array(
								'ViewHelper',
						       ));
		$cancel->setDecorators(array(
								'ViewHelper',
									)
						       );
		$this->addDisplayGroup(array('submit','cancel'),'action');
		$action = $this->getDisplayGroup('action');
		$action->setDecorators(array(
                'FormElements',
                'Fieldset',
                array('HtmlTag',array('tag'=>'div','class'	=> 'col-md-offset-2'))
        ));
	}
}